/*
 category: CTP Web 2.0
 name: New Container Class
 toolTip: New Container Class
 toolbar: true
 language: text/javascript
 icon: com.aptana.ide.snippets/icons/wrap_js_function.png
 prompt(classname):类名，如：layout
 prompt(author):你的大名，如：kfzx-renhm
 */

//注册命名空间
Namespace.register("ctp.ui");
//加载语言包，若没有，可屏蔽此句
//ctp.core.lang.load("../../js/ctp/${classname}/lang/");
/**
 * @class 面板
 * @extends	ctp.ui.container
 * @param {Object} settings
 * <p>
 * settings里面的参数说明
 * <ul>
 * settings参数说明：
 * <li><em>{String}</em> id 		    - ${classname}的id，不输入时会自动生成一个</li>
 * ...
 * </ul>
 *
 * @return	{ctp.ui.${{classname}}}	${classname}对象
 * @version	 1.0
 * @since	 1.0
 * @author	kfzx-renhm
 * @example
 * ......
 * 
 * @example
 * ......
 * 
 */
ctp.ui.${classname} = function(settings){
	//记录当前上下文
	var _pkgContext = "ctp.ui.${classname}(v " + (this.version || "n/a") + ")";
	try {
		ctp.core.log.info(_pkgContext + " -> id: " + (settings.id || "n/a"), "initialize begin...");
		
		//初始化配置(父类方法)
		this.init(settings);
		
		// TODO 实现自己的初始化配置过程		
		
				
		//组件渲染（创建DOM）
		if (settings.renderTo) {
			this.renderTo();
		}
		
		//初始化后置操作（父类方法）
		this.afterInit(settings);
		
		ctp.core.log.info(_pkgContext + " -> id: " + (this.getId() || "n/a"), "initialize end !");
	} 
	catch (e) {
		ctp.core.log.err(_pkgContext + " initializing id: " + (this.getId() || "n/a"), e.message);
	}
}

// 原型扩展的成员(非特权)方法及属性
ctp.ui.${classname}.prototype = {
	/**
	 * 组件版本号
	 * @private
	 */
	version: '1.0',
	
	/**
	 * 组件类型
	 * @private
	 */
	type: '${classname}',
	
	/**
	 * 上下文
	 * @private
	 */
	ctpPackage: 'ctp.ui.${classname}',
	
	/* >>>>>>>>>>>>>>>>>可覆盖的Component方法<<<<<<<<<<<<<<<<<<<<<<
	getCtpWebType: function(){},
	getPkgContext: function(){},
	getFnContext: function(fnName){},
	init: function(settings){},
	afterInit:function(){},
	getSettings:function(){},
	getInitSettings:function(){},
	getId:function(){},
	getName:function(){},
	getDomId:function(){},
	getJqDom:function(){},
	show:function(){},
	hide:function(){},
	destroy:function(){},
	getWidth:function(){},
	getHeight:function(){},
	setWidth:function(w,callresize){},
	setHeight:function(h,callresize){},
	setSize:function(w,h){},
	removeJqDoms:function(){},
	*/
	
	/**
	 * 取得组件默认配置
	 * @private
	 */
	getDefaultSettings: function(){
		// TODO: 实现父类方法
		return {
			id: '',			
			renderTo: '' // 继承的容器ID，默认为BODY
		};
		
	},
		
	
	/**
	 * 取得组件DOM的HTML
	 * @return	{String}
	 * @version	 1.0
	 * @since	 1.0
	 * @author	kfzx-renhm
	 * @example
	 * ....
	 *
	 * @example
	 * ...
	 *
	 */
	getTemplate: function(cfg){
		// TODO 实现父类方法
		var _fnContext = this.getFnContext('getTemplate()');
		try {
			
		} 
		catch (e) {
			ctp.core.log.err(_fnContext, e.message);
		}
	},
	
		
	/**
	 * 组件大小适应
	 * @ignore 暂时没用到
	 * @param {Object} w
	 * @param {Object} h
	 * @version	 1.0
	 * @since	 1.0
	 * @author	kfzx-renhm
	 * @example
	 * ....
	 *
	 * @example
	 * ...
	 */
	onResize: function(w, h){
		// TODO 实现父类方法
		var _fnContext = this.getFnContext('onResize()');
		try {
		} 
		catch (e) {
			ctp.core.log.err(_fnContext, e.message);
		}
	},
	
	/**
	 * 改变组件大小
	 * @param {Object} w
	 * @param {Object} h
	 * @version	 1.0
	 * @since	 1.0
	 * @author	kfzx-renhm
	 * @example
	 * ....
	 *
	 * @example
	 * ...
	 */
	resize: function(w, h){
		// TODO 实现父类方法
		var _fnContext = this.getFnContext('resize(w,h)');
		try {		
			
		} 
		catch (e) {
			ctp.core.log.err(_fnContext, e.message);
		}
		
	},
	

	/**
	 * 将组件渲染到指定位置
	 *
	 * @version	 1.0
	 * @since	 1.0
	 * @author	kfzx-lixy01
	 * @param {String|ctp.ui|jQuery} tar 	目标容器ID或CTP组件对象或jQuery对象
	 * @example
	 * obj.renderTo('div1'); //渲染到ID为div1的容器中
	 * obj.renderTo(${classname}1); //渲染到${classname}1对象(CTP组件对象)中
	 * obj.renderTo($('body')); //渲染到body中(jQuery对象)
	 */
	renderTo: function(tar){
		// TODO 实现父类方法
		var _fnContext = this.getFnContext('renderTo(tar)');
		try {
			tar = tar || this.getSettings().renderTo;
			if (!this.rendered && tar) {
				this.getSettings().renderTo = tar;
				
				var html = this.getTemplate(this.getSettings());
				
				this.jqDom = $(html);
				this.contentJqDom = $("#" + this.getContentDomId(), this.jqDom);
				
				this.getSettings().renderTo = ctp.core.initRender(this.jqDom, this.getSettings());
				
				if (!this.preRenderChild) {
					this.renderItems();
				}
				
				this.rendered = true;
				
				this.initEvent();
			}
		} 
		catch (e) {
			ctp.core.log.err(_fnContext, e.message);
		}
	},
	
	
	/**
	 * 组件渲染后进行动态计算
	 *
	 * @version	 1.0
	 * @since	 1.0
	 * @author	kfxx-lixy01
	 * @example
	 * obj.render();
	 *
	 */
	render: function(){
		// TODO 实现父类方法
		this.renderTo(this.getSettings().renderTo);
	},
	
	/* >>>>>>>>>>>>>>>>>可覆盖的container方法<<<<<<<<<<<<<<<<<<<<<<
	resizeItems:function(){}
	getItems:function(){},
	renderItems:function(){},
	renderItem:function(item,$tar,tarWidth,tarHeight){},
	getContentDomId:function(){},
	getContentJqDom:function(){},
	append:function(item){},
	getObjs:function(type){},
	getObj:function(id){},
	delObjs:function(ids){},
	getValidateArray:function(){},
	getSubmitArray:function(){},
	reset:function(){},
	remove:function(){},
	*/	
	

	/**
	 * 初始化事件
	 * @version	 1.0
	 * @since	 1.0
	 * @author	kfxx-lixy01
	 * @example
	 * ......
	 *
	 */
	initEvent: function(){
		// TODO 实现父类方法
		
		//保存当前对象的引用
		var Me = this;
		var _fnContext = this.getFnContext('initEvent()');
		try {
			if (this.getSettings().closable) {
				this.buttonClose = $('div.ctp-caption-btnClose', this.jqDom);
			}
			if (this.getSettings().btnstatus) {
				this.buttonMax = $('div.ctp-caption-btnMax', this.jqDom);
			}
			if (this.getSettings().collapsible) {
				this.buttonColl = $('div.ctp-caption-btnlen', this.jqDom);
				this.${classname}Body = $('div.side-bg', this.jqDom);
				this.buttonColl.click(function(){
					if (Me.collapsed) {
						Me.${classname}Body.show();
						Me.collapsed = false;
					}
					else {
						Me.${classname}Body.hide();
						Me.collapsed = true;
					}
					
				});
			}
		} 
		catch (e) {
			ctp.core.log.err(_fnContext, e.message);
		}
	},
	

	
	/////////////////////////////////////////////////////
	/////////////////////////////////////////////////////
	// TODO 实现组件方法
	/**
	 * 例子
	 * @return	{jQuery}	组件的jQuery对象
	 * @version	 1.0
	 * @since	 1.0
	 * @author	${author}
	 * @example
	 * obj.getJqDom();
	 */
	fn: function(){
		var _fnContext = this.getFnContext('fn');
		try {
			
		} 
		catch (e) {
			
		}
	}
}

ctp.Class.create(ctp.ui.${classname} , ctp.ui.container);
/**
 * @fileOverview
 * 
 * <pre>
 * 面板组件
 * 路径：ctp/ui/${classname}
 * 命名空间:ctp.ui
 * </pre>
 *  
 * @version 1.0
 * 优化后初始版本
 * 
 * @author ${author}
 */